package web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.NoticeDao;
import dao.NoticeDaoFactory;

/*
 * 作用：删除1条记录
 */
@WebServlet("/DeteleNoticeServlet")
public class DeteleNoticeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1.获取客户端传过来的参数
		String id = request.getParameter("id");
		
		//2.调用service（本例直接是dao）执行，获取返回值
		NoticeDao dao = new NoticeDaoFactory().factory();
		boolean flag = dao.deleteById(id);
		
		//3.根据返回值，跳转到
		if (flag){
			response.sendRedirect("index.html");
		}else{
			response.sendRedirect("error.jsp");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
